({
    data: {
        resultdata: {},
        dbConn: Program.data.dbConn,
        WorkId: Program.data.WorkId,
        requestBody: Program.data.requestBody,
        GoodsModel: {
            model: {
                GoodsId: 0,
                ShopId: 0,
                GoodsName: "",
                Goodspe: "",
                GoodsBrand: "",
                GoodsClass: "",
                GoodsStock: "",
                GoodsRetailPrice: "",
                GoodsMarketPrice: "",
                GoodsMainPic: "",
                GoodsBanner: "",
                GoodsDescribe: "",
                GoodsSort: "",
                GoodsStatus: 0,
                IsNewGoods: 0,
                IsHotGoods: 0,
                ExtendDescribe: "",
                GoodsKey: "",
                SortIntroduce: "",
                WorkId: 1
            },
            tablename: "Mall_Goods",
            key: "GoodsId",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {},
            WorkId: MirthAPI.ProgramData('workid') //机构ID
        },
        GoodsSpecModel: {
            model: {
                SpecItemId: 0,
                SpecId: 0,
                GoodsId: 0,
                SpecImg: '',
                SpecName: '',
                SpecItemImg: '',
                SpecItemName: ''

            },
            tablename: "Mall_GoodsSpec",
            key: "SpecItemId",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {},
            WorkId: MirthAPI.ProgramData('workid')
        },
        GoodSpecDetailModel: {
            model: {
                GoodsSpecDetailId: 0,
                GoodsId: 0,
                SpecCom: '',
                SpecItemCom: '',
                ProductSpec: '',
                GoodsStock: 0,
                GoodsRetailPrice: 0,
                GoodsMarketPrice: 0,
                GoodsSpecImg: ''
            },
            tablename: "Mall_GoodsSpecDetail",
            key: "GoodsSpecDetailId",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {},
            WorkId: MirthAPI.ProgramData('workid')
        },
        RefundModel: {
            model: {
                RefundId: 0,
                RefundNo: "",
                OrderNo: "",
                RefundDate: "yyyy-MM-dd HH:mm:ss",
                RefundFee: 0,
                RefundType: 0,
                CargoStatus: 0,
                RefundStatus: 0,
                RefundDesc: "",
                TradeNo: "",
                SuccessTime: "yyyy-MM-dd HH:mm:ss",
                RefundRequestSource: 0,
                WorkId: 0,
                BillNo: "",
                RemoveShareBillNo: "",
                AuditTime: "yyyy-MM-dd HH:mm:ss",
                AuditStatus: 0,
                RefundMemo: "",
                Imgs: "",
                UserId: "",
                AuditMemo: "",
            },
            tablename: "Mall_Refund",
            key: "RefundId",
            val: "0",
            objval: {},
            WorkId: LobsterAPI.ProgramData('workid')
        },
        RefundLogModel: {
            model: {
                LogId: 0,
                OrderNo: "",
                RefundNo: "",
                Memo: "",
                OperationTime: "yyyy-MM-dd HH:mm:ss",
                Operator: "",
            },
            tablename: "Mall_RefundLog",
            key: "LogId",
            val: "0",
            objval: {},
        },
        OrderModel: {
            model: {
                OrderId: 0,
                OrderNo: "",
                PayState: 0,
                PayType: 0,
                TotalFee: 0,
                OrderStatus: 0,
                CreateTime: "yyyy-MM-dd HH:mm:ss",
                OrderMemo: "",
                UserId: "",
                DelFlag: 0,
                WorkId: 0,
            },
            tablename: "Mall_Order",
            key: "OrderId",
            val: "0",
            objval: {},
            WorkId: LobsterAPI.ProgramData('workid')
        },
        OrderLogisticsModel: {
            model: {
                OrderLogisticsId: 0,
                RefundNo: "",
                OrderNo: "",
                LogisticsNo: "",
                LogisticsCompany: "",
                Status: 0,
                Fee: 0,
            },
            tablename: "Mall_OrderLogistics",
            key: "OrderLogisticsId",
            val: "0",
            objval: {},
        }
    },
    //实现增删改查示例API控制器
    main: function (funname) {
        var self = this;
        self.data.dbConn = PublicFunction.setdbconn('10.0.4.5:1433', 'CloudMall', 'sa', 'Lobster@123');
        //查询
        if (funname == "Mall.getgoods") {
            var page = PublicFunction.RequestQuery("page", 0);
            var limit = PublicFunction.RequestQuery("limit", 0);
            var Name = PublicFunction.RequestQuery("Name", '');
            var res = self.getgoods(page, limit, Name);
            self.data.resultdata.data = res.data;
            self.data.resultdata.count = res.count;
        } else if (funname == "Mall.getgoodsSpec") {
            var page = PublicFunction.RequestQuery("page", 0);
            var limit = PublicFunction.RequestQuery("limit", 0);
            var Name = PublicFunction.RequestQuery("Name", '');
            var goodsid = PublicFunction.RequestQuery("goodsid", 0);
            var res = self.getgoodsSpec(page, limit, Name, goodsid);
            self.data.resultdata.data = res.data;
            self.data.resultdata.count = res.count;
        } else if (funname == "Mall.getproduct") {
            var page = PublicFunction.RequestQuery("page", 0);
            var limit = PublicFunction.RequestQuery("limit", 0);
            var goodsid = PublicFunction.RequestQuery("goodsid", 0);
            var res = self.getproduct(page, limit, goodsid);
            self.data.resultdata.data = res.data;
            self.data.resultdata.count = res.count;
        } else if (funname == "Mall.getorder") {
            var page = PublicFunction.RequestQuery("page", 0);
            var limit = PublicFunction.RequestQuery("limit", 0);
            var OrderNo = PublicFunction.RequestQuery("OrderNo", '');
            var OrderStatus = PublicFunction.RequestQuery("OrderStatus", 0);
            var res = self.getorder(page, limit, OrderNo, OrderStatus);
            self.data.resultdata.data = res.data;
            self.data.resultdata.count = res.count;
        }
        else if (funname == "Mall.changeStatus") {
            var mod = JSON.parse(self.data.requestBody);
            mod.model = JSON.parse(mod.model)
            self.changeStatus(mod);
        }
        else if (funname == "Mall.deletegoods") {
            var mod = JSON.parse(self.data.requestBody);
            mod.model = JSON.parse(mod.model)
            self.deletegoods(mod);
        }
        else if (funname == "Mall.deletegoodsSpec") {
            var mod = JSON.parse(self.data.requestBody);
            mod.model = JSON.parse(mod.model)
            self.deletegoodsSpec(mod);
        }
        else if (funname == "Mall.deletegoodsSpecdetail") {
            var mod = JSON.parse(self.data.requestBody);
            mod.model = JSON.parse(mod.model)
            self.deletegoodsSpecdetail(mod);
        }
        else if (funname == "Mall.getGoodsType") {
            self.data.resultdata.data = self.getGoodsType();
        }
        else if (funname == "Mall.savegoods") {
            var goods = JSON.parse(self.data.requestBody);
            self.savegoods(goods);
        }
        else if (funname == "Mall.editproductsave") {
            var spec = JSON.parse(self.data.requestBody);
            self.editproductsave(spec);
        }
        else if (funname == "Mall.savegoodsSpec") {
            var spec = JSON.parse(self.data.requestBody);
            self.savegoodsSpec(spec);
        }
        else if (funname == "Mall.addproduct") {
            var mod = JSON.parse(self.data.requestBody);
            self.addproduct(mod);
        }
        else if (funname == "Mall.getspecdic") {
            self.data.resultdata.data = self.getspecdic();
        }
        else if (funname == "Mall.getbaseinfo") {
            self.data.resultdata.data = self.getbaseinfo();
        }
        else if (funname == "Mall.getuploadurl") {
            self.data.resultdata.data = self.getUploadUrl();
        } else if (funname == "Mall.ConfirmGetGoods") {//确认收货
            var model = JSON.parse(self.data.requestBody);
            self.data.resultdata = self.ConfirmGetGoods(model);
        }
        else if (funname == "Mall.Audit") {//管理员审核
            var model = JSON.parse(self.data.requestBody);
            self.data.resultdata = self.Audit(model);
        }
        else if (funname == "Mall.GetBackStageRefundList") {//后台退款列表 
            var page = PublicFunction.RequestQuery("page", 0);
            var limit = PublicFunction.RequestQuery("limit", 0);
            var refundNo = PublicFunction.RequestQuery("refundNo", '');
            var refundStatus = PublicFunction.RequestQuery("refundStatus", -1);
            var sdate = PublicFunction.RequestQuery("sdate", 0);
            var edate = PublicFunction.RequestQuery("edate", 0);
            self.data.resultdata = self.GetBackStageRefundList(page, limit, refundNo, refundStatus, sdate, edate);
        }
        else if (funname == "Mall.GetRefundGoodsList") {//获取退款商品详情
            var refundNo = PublicFunction.RequestQuery("refundNo", '');
            self.data.resultdata = self.GetRefundGoodsList(refundNo);
        }
        else if (funname == "Mall.GetLogistics") {//获取物流
            var refundNo = PublicFunction.RequestQuery("refundNo", '');
            self.data.resultdata = self.GetLogistics(refundNo);
        }
        else if (funname == "Mall.GetOrderLogistics") {//获取物流
            var orderNo = PublicFunction.RequestQuery("orderNo", '');
            self.data.resultdata = self.GetOrderLogistics(orderNo);
        }
        else if (funname == "Mall.GetBackStageOrderList") {//后台订单列表
            var page = PublicFunction.RequestQuery("page", 0);
            var limit = PublicFunction.RequestQuery("limit", 0);
            var orderNo = PublicFunction.RequestQuery("orderNo", '');
            var orderStatus = PublicFunction.RequestQuery("orderStatus", -1);
            var sdate = PublicFunction.RequestQuery("sdate", 0);
            var edate = PublicFunction.RequestQuery("edate", 0);
            self.data.resultdata = self.GetBackStageOrderList(page, limit, orderNo, orderStatus, sdate, edate);
        }
        else if (funname == "Mall.SendGoods") {//发货
            var model = JSON.parse(self.data.requestBody);
            self.data.resultdata = self.SendGoods(model);
        } else if (funname == "Mall.GetOrderGoodsList") {//获取订单商品详情
            var orderNo = PublicFunction.RequestQuery("orderNo", '');
            self.data.resultdata = self.GetOrderGoodsList(orderNo);
        }
        return self.data.resultdata;
    },

    getGoodsType: function () {
        var self = this;
        var strsql = "SELECT * FROM Mall_GoodsType WHERE WorkId = ? ";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(self.data.WorkId);
        var data = MirthAPI.OrmMsSql.GetJsonData(self.data.dbConn, strsql, dbparams);
        return { data: data };
    },
    changeStatus: function (mod) {
        MirthAPI.TrackLog("mod", mod);
        var self = this;
        self.data.GoodsModel.val = mod.model.GoodsId;
        var newgoods = mod.model
        newgoods.GoodsStatus = mod.Status
        self.data.GoodsModel.objval = newgoods;
        MirthAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.GoodsModel);
        return {code:0,msg:"操作成功"};
    },
    deletegoods: function (mod) {
        var self = this;
        self.data.GoodsModel.val = mod.model.GoodsId;
        var newgoods = mod.model
        self.data.GoodsModel.objval = newgoods;
        MirthAPI.OrmMySql.DeleteModel(self.data.dbConn, self.data.GoodsModel);
        return {code:0,msg:"操作成功"};
    },
    getgoods: function (page, limit, Name) {
        var self = this;
        var pageInfo = {};
        pageInfo.key = "GoodsId desc";
        pageInfo.page = page;
        pageInfo.perPage = limit;
        pageInfo.totalRecord = 0;
        pageInfo.totalPage = 0;
        var strsql = "SELECT a.*,b.GoodsTypeId,b.TypeName AS GoodsClassName  from Mall_Goods a LEFT JOIN dbo.Mall_GoodsType b ON a.GoodsClass = b.GoodsTypeId WHERE a.WorkId = ?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(self.data.WorkId);
        if ((Name || "") != "") {
            strsql += " and a.GoodsName Like ?";
            dbparams.add('%' + Name + '%');
        }
        var data = ORMFunction.GetJsonData(self.data.dbConn, strsql, dbparams, pageInfo);

        return { data: data, count: pageInfo.totalRecord };
    },
    getgoodsSpec: function (page, limit, Name, goodsid) {

        var self = this;
        var pageInfo = {};
        pageInfo.key = "SpecId";
        pageInfo.page = page;
        pageInfo.perPage = limit;
        pageInfo.totalRecord = 0;
        pageInfo.totalPage = 0;
        var strsql = "SELECT a.*,b.GoodsName FROM dbo.Mall_GoodsSpec a LEFT JOIN dbo.Mall_Goods b ON a.GoodsId = b.GoodsId WHERE b.WorkId = ?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(self.data.WorkId);
        if ((Name || "") != "") {
            strsql += " and a.SpecItemName Like ?";
            dbparams.add('%' + Name + '%');
        }
        if (goodsid > 0) {
            strsql += " and a.GoodsId =  ?";
            dbparams.add(goodsid);
        }
        var data = MirthAPI.OrmMsSql.GetJsonData(self.data.dbConn, strsql, dbparams, pageInfo);

        return { data: data, count: pageInfo.totalRecord };
    },
    getproduct: function (page, limit, goodsid) {
        var self = this;
        var pageInfo = {};
        pageInfo.key = "GoodsSpecDetailId desc";
        pageInfo.page = page;
        pageInfo.perPage = limit;
        pageInfo.totalRecord = 0;
        pageInfo.totalPage = 0;
        var strsql = "SELECT a.*,b.GoodsName FROM dbo.Mall_GoodsSpecDetail a LEFT JOIN dbo.Mall_Goods b ON a.GoodsId = b.GoodsId WHERE b.WorkId = ?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(self.data.WorkId);
        if (goodsid > 0) {
            strsql += " and a.GoodsId =  ?";
            dbparams.add(goodsid);
        }
        var data = MirthAPI.OrmMsSql.GetJsonData(self.data.dbConn, strsql, dbparams, pageInfo);

        return { data: data, count: pageInfo.totalRecord };
    },
    getorder: function (page, limit, OrderNo, OrderStatus) {
        var self = this;
        var pageInfo = {};
        pageInfo.key = "OrderId desc";
        pageInfo.page = page;
        pageInfo.perPage = limit;
        pageInfo.totalRecord = 0;
        pageInfo.totalPage = 0;
        var strsql = "SELECT * from Mall_Order a WHERE 1=1";
        var dbparams = Packages.java.util.ArrayList();
        //dbparams.add(self.data.WorkId);
        if ((OrderNo || "") != "") {
            strsql += " and a.OrderNo = ?";
            dbparams.add(OrderNo);
        }
        if (OrderStatus > -1) {
            strsql += " and a.OrderStatus =  ?";
            dbparams.add(OrderStatus);
        }
        var data = MirthAPI.OrmMsSql.GetJsonData(self.data.dbConn, strsql, dbparams, pageInfo);

        return { data: data, count: pageInfo.totalRecord };
    },
    savegoods: function (goods) {


        var self = this;
        self.data.GoodsModel.val = goods.GoodsId;
        self.data.GoodsModel.objval = goods;
        MirthAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.GoodsModel);
        return {code:0,msg:"操作成功"};
    },
    editproductsave: function (goods) {


        var self = this;
        self.data.GoodSpecDetailModel.val = goods.GoodsSpecDetailId;
        self.data.GoodSpecDetailModel.objval = goods;
        MirthAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.GoodSpecDetailModel);
        return {code:0,msg:"操作成功"};
    },
    savegoodsSpec: function (spec) {

        var self = this;
        self.data.GoodsSpecModel.val = spec.SpecItemId;
        self.data.GoodsSpecModel.objval = spec;
        MirthAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.GoodsSpecModel);
        return {code:0,msg:"操作成功"};
    },
    addproduct: function (mod) {
        //MirthAPI.TrackLog("mod" ,mod);
        var self = this;
        var specids = mod.allspedid.split(',')
        var arr = [];
        var SpecCom = '';
        for (let i = 0; i < specids.length; i++) {
            var num = mod["SpecIdSelect-" + specids[i]].split(',')
            arr.push(num)
            SpecCom += "_" + specids[i]
        }
        SpecCom = SpecCom.substring(1)
        var sarr = [[]];
        //MirthAPI.TrackLog("arr" ,arr);
        for (var i = 0; i < arr.length; i++) {
            var tarr = [];
            for (var j = 0; j < sarr.length; j++)
                for (var k = 0; k < arr[i].length; k++)
                    tarr.push(sarr[j].concat('_' + arr[i][k]).toString());
            sarr = tarr;
        }
        for (let i = 0; i < sarr.length; i++) {
            sarr[i] = sarr[i].substring(1)
        }
        //MirthAPI.TrackLog("sarr" ,sarr);
        mod.goodsSpec = JSON.parse(mod.goodsSpec)
        MirthAPI.TrackLog("mod.goodsSpec", mod.goodsSpec);
        for (let i = 0; i < sarr.length; i++) {
            MirthAPI.TrackLog("for" + i, i);
            var SpecItemId = sarr[i].split('_')
            var text = ''
            for (let j = 0; j < SpecItemId.length; j++) {
                var e = SpecItemId[j];
                for (let k = 0; k < mod.goodsSpec.length; k++) {
                    var obj = mod.goodsSpec[k];
                    if (obj.SpecId == specids[j] && obj.SpecItemId == e) {
                        text += '，' + obj.SpecItemName
                    }
                }
            }
            text = text.substring(1)
            self.data.GoodSpecDetailModel.val = 0;
            self.data.GoodSpecDetailModel.objval = {
                GoodsSpecDetailId: 0,
                GoodsId: mod.GoodsId,
                SpecCom: SpecCom,
                SpecItemCom: sarr[i],
                ProductSpec: text,
                GoodsStock: mod.GoodsStock,
                GoodsRetailPrice: mod.GoodsRetailPrice,
                GoodsMarketPrice: mod.GoodsMarketPrice,
                GoodsSpecImg: mod.GoodsSpecImg
            }
            MirthAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.GoodSpecDetailModel);
        }
        return {code:0,msg:"操作成功"};
    },
    deletegoodsSpec: function (mod) {
        var self = this;
        self.data.GoodsSpecModel.val = mod.model.SpecItemId;
        var newspec = mod.model
        self.data.GoodsSpecModel.objval = newspec;
        MirthAPI.OrmMySql.DeleteModel(self.data.dbConn, self.data.GoodsSpecModel);
        return {code:0,msg:"操作成功"};
    },
    deletegoodsSpecdetail: function (mod) {
        var self = this;
        self.data.GoodSpecDetailModel.val = mod.model.GoodsSpecDetailId;
        var newspec = mod.model
        self.data.GoodSpecDetailModel.objval = newspec;
        MirthAPI.OrmMySql.DeleteModel(self.data.dbConn, self.data.GoodSpecDetailModel);
        return {code:0,msg:"操作成功"};
    },
    getspecdic: function () {
        return MirthAPI.AppFunction.GetAppBaseDict(MirthAPI.ProgramData('appid'), 8138)
    },
    getbaseinfo: function () {
        return {
            WorkId: this.data.WorkId,
            apiGateway: JSON.parse(MirthAPI.AppFunction.GetSystemConfigs(this.data.WorkId, '10', 'apiGateway')).apiGateway,
            localapiGateway: 'http://localhost:8000'
        }
    },
    getUploadUrl: function () {
        var appId = "APP20200616102057595";//MirthAPI.ProgramData('appkey');
        var apiGateway = MirthAPI.apiGateway;
        var url = apiGateway + "/common/v1/OSS/UploadFile" + "?appKey=" + appId;
        return { url: url };
    },
    ConfirmGetGoods(model) {
        var self = this;
        try {
            self.data.dbConn.setAutoCommit(false);
            var strsql = "select * from Mall_Refund where RefundNo=?";
            var dbparams = Packages.java.util.ArrayList();
            dbparams.add(model.RefundNo);
            var refund = ORMFunction.GetJsonObject(self.data.dbConn, strsql, dbparams);
            if (!refund.RefundId)
                return { code: 1, msg: "找不到退款订单" };
            refund.RefundStatus = 3;
            self.data.RefundModel.objval = refund;
            LobsterAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.RefundModel);
            var refundlog =
            {
                OrderNo: refund.OrderNo,
                RefundNo: refund.RefundNo,
                Memo: "商家确认收货",
                OperationTime: self.getdatetime(),
                Operator: "管理员"
            };
            self.data.RefundLogModel.objval = refundlog;
            LobsterAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.RefundLogModel);
            if (refund.RefundType == 2) {
                var res = LobsterAPI.AppFunction.CallOutService(LobsterAPI.ProgramData("appid"), "wallet.wallet.transactionrefund", {
                    SubMchId: '20220505085609644323',
                    BusinessOrderNo: refund.OrderNo,
                    BusinessRefundNo: refund.RefundNo,
                    RefundRealFee: parseFloat(refund.RefundFee) * 100, //单位分
                    RefundDesc: '用户申请退货退款',//商品描述 
                });
                LobsterAPI.TrackLog("CallOutService", res);
                if (res.code == 1) {
                    throw res.msg;
                }
            }
            self.data.dbConn.commit();
            return { code: 0, data: { refund: refund } };
        } catch (e) {
            self.data.dbConn.rollback();
            return { code: 1, msg: e.message };
        }
    },
    Audit(model) {
        var self = this;
        try {
            self.data.dbConn.setAutoCommit(false);
            var strsql = "select * from Mall_Refund where RefundNo=?";
            var dbparams = Packages.java.util.ArrayList();
            dbparams.add(model.RefundNo);
            var refund = ORMFunction.GetJsonObject(self.data.dbConn, strsql, dbparams);
            if (!refund.RefundId)
                return { code: 1, msg: "找不到退款订单" };
            refund.AuditStatus = model.AuditStatus;
            refund.AuditTime = self.getdatetime();
            refund.AuditMemo = model.AuditMemo;
            refund.RefundStatus = model.AuditStatus == 1 ? 1 : 99;
            self.data.RefundModel.objval = refund;
            LobsterAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.RefundModel);
            var refundlog =
            {
                OrderNo: refund.OrderNo,
                RefundNo: refund.RefundNo,
                Memo: model.AuditStatus == 1 ? "审核通过" : "审核不通过",
                OperationTime: self.getdatetime(),
                Operator: "管理员"
            };
            self.data.RefundLogModel.objval = refundlog;
            LobsterAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.RefundLogModel);
            if ((refund.RefundType == 1 || refund.CargoStatus == 1) && model.AuditStatus == 1) {
                var res = LobsterAPI.AppFunction.CallOutService(LobsterAPI.ProgramData("appid"), "wallet.wallet.transactionrefund", {
                    SubMchId: '20220505085609644323',
                    BusinessOrderNo: refund.OrderNo,
                    BusinessRefundNo: refund.RefundNo,
                    RefundRealFee: parseFloat(refund.RefundFee) * 100, //单位分
                    RefundDesc: '用户申请仅退款',//商品描述 
                });
                LobsterAPI.TrackLog("CallOutService", res);
                if (res.code == 1) {
                    throw res.msg;
                }
            }
            self.data.dbConn.commit();
            return { code: 0, data: { refund: refund } };
        } catch (e) {
            self.data.dbConn.rollback();
            return { code: 1, msg: e.message };
        }
    },
    GetBackStageRefundList(page, limit, refundNo, refundStatus, sdate, edate) {
        var self = this;
        var pageInfo = {};
        pageInfo.key = "RefundDate desc";
        pageInfo.page = page;
        pageInfo.perPage = limit;
        pageInfo.totalRecord = 0;
        pageInfo.totalPage = 0;
        var dbparams = Packages.java.util.ArrayList();
        var strsql = "select * from Mall_Refund where WorkId=?";
        dbparams.add(self.data.WorkId);
        if (refundStatus > -1) {
            strsql += " and RefundStatus = ?";
            dbparams.add(refundStatus);
        }
        if ((refundNo || "") != "") {
            strsql += " and RefundNo like ?";
            dbparams.add('%' + refundNo + '%');
        }
        if (sdate != "") {
            strsql += " and RefundDate>=?";
            dbparams.add(sdate + " 00:00:01");
        }
        if (edate != "") {
            strsql += " and RefundDate<?";
            dbparams.add(edate + " 23:23:59");
        }
        var data = ORMFunction.GetJsonData(self.data.dbConn, strsql, dbparams, pageInfo);
        return { code: 0, data: data, count: pageInfo.totalRecord };
    },
    GetRefundGoodsList(refundNo) {
        var strsql = "select * from Mall_RefundGoods where RefundNo=?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(refundNo);
        var goodslist = ORMFunction.GetJsonData(self.data.dbConn, strsql, dbparams);
        return { code: 0, data: { goodslist: goodslist } };
    },
    GetLogistics(refundNo) {
        var strsql = "select * from Mall_OrderLogistics where RefundNo=?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(refundNo);
        var logistics = ORMFunction.GetJsonObject(self.data.dbConn, strsql, dbparams);
        return { code: 0, data: { logistics: logistics } };
    },
    GetOrderLogistics(orderNo) {
        var strsql = "select * from Mall_OrderLogistics where OrderNo=?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(orderNo);
        var logistics = ORMFunction.GetJsonObject(self.data.dbConn, strsql, dbparams);
        return { code: 0, data: { logistics: logistics } };
    },
    GetBackStageOrderList(page, limit, orderNo, orderStatus, sdate, edate) {
        var self = this;
        var pageInfo = {};
        pageInfo.key = "CreateTime desc ";
        pageInfo.page = page;
        pageInfo.perPage = limit;
        pageInfo.totalRecord = 0;
        pageInfo.totalPage = 0;
        var dbparams = Packages.java.util.ArrayList();
        var strsql = "select a.*,b.TradeNo,b.PayFee,b.TimeEnd,c.NickName,c.TelPhone, \
        convert(varchar(2000), (SELECT GoodsName+',' from Mall_OrderGoods where OrderNo=a.OrderNo FOR XML PATH(''))) as GoodsName from Mall_Order a\
        left join Mall_OrderPay b\
        on a.OrderNo=b.OrderNo\
        left join mall_Member c\
        on a.userid=c.userid\
        where WorkId=? ";
        dbparams.add(self.data.WorkId);
        if (orderStatus > -1) {
            strsql += " and a.OrderStatus = ?";
            dbparams.add(orderStatus);
        }
        if ((orderNo || "") != "") {
            strsql += " and a.OrderNo like ?";
            dbparams.add('%' + orderNo + '%');
        }
        if (sdate != "") {
            strsql += " and a.CreateTime>=?";
            dbparams.add(sdate + " 00:00:01");
        }
        if (edate != "") {
            strsql += " and a.CreateTime<?";
            dbparams.add(edate + " 23:23:59");
        }
        var data = ORMFunction.GetJsonData(self.data.dbConn, strsql, dbparams, pageInfo);
        return { code: 0, data: data, count: pageInfo.totalRecord };
    },
    SendGoods(model) {
        var self = this;
        try {
            self.data.dbConn.setAutoCommit(false);
            var strsql = "select * from Mall_Order where OrderNo=? and OrderStatus=1";
            var dbparams = Packages.java.util.ArrayList();
            dbparams.add(model.OrderNo);
            var order = ORMFunction.GetJsonObject(self.data.dbConn, strsql, dbparams);
            if (!order.OrderId)
                return { code: 1, msg: "找不到订单" };
            order.OrderStatus = 2;
            order.DeliveryTime = self.getdatetime();
            self.data.OrderModel.objval = order;
            LobsterAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.OrderModel);
            model.Fee = 0;
            self.data.OrderLogisticsModel.objval = model;
            LobsterAPI.OrmMySql.SaveModel(self.data.dbConn, self.data.OrderLogisticsModel);
            self.data.dbConn.commit();
        } catch (e) {
            self.data.dbConn.rollback();
            return { code: 1, msg: e.message };
        }
    },
    GetOrderGoodsList(orderNo) {
        var strsql = "select * from Mall_OrderGoods where OrderNo=?";
        var dbparams = Packages.java.util.ArrayList();
        dbparams.add(orderNo);
        var goodslist = ORMFunction.GetJsonData(self.data.dbConn, strsql, dbparams);
        return { code: 0, data: { goodslist: goodslist } };
    },

    getdatetime: function () {
        var self = this;
        return LobsterAPI.getCurrTime(self.data.dbConn, "yyyyMMddhhmmss", 0, 0, 0, 0);
    },
    generateOrderNo: function () {
        var self = this;
        var currentDateStr = LobsterAPI.getCurrTime(self.data.dbConn, "yyyyMMddhhmmss", 0, 0, 0, 0);
        currentDateStr = currentDateStr.replace(/-/gi, "").replace(/:/gi, "").replace(" ", "")
        return currentDateStr + Math.ceil(Math.random() * 1000000);
    },
    formateDate: function (fmt, date) {
        var ret;
        var opt = {
            "y+": date.getFullYear().toString(),
            "M+": (date.getMonth() + 1).toString(),
            "d+": date.getDate().toString(),
            "H+": date.getHours().toString(),
            "m+": date.getMinutes().toString(),
            "s+": date.getSeconds().toString()
        };
        for (var k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            };
        };
        return fmt;
    },
})